package com.csweimei.rentmanagementtreasure.tenant.viewModel;

import static com.csweimei.rentmanagementtreasure.base.AppConfig.BUNDLE_KEY;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.csweimei.rentmanagementtreasure.base.AppConfig;
import com.csweimei.rentmanagementtreasure.http.entity.CustomerBean;
import com.csweimei.rentmanagementtreasure.tenant.ui.act.customer.CustomerInfoActivity;
import com.csweimei.rentmanagementtreasure.utils.ValidateUtils;
import com.csweimei.rentmanagementtreasure.utils.permission.RxPermissionsUtils;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class CustomerItemVM extends MultiItemViewModel {
    public ObservableField<CustomerBean.DataDTO> info = new ObservableField<>();

    ChooseCustomerVM chooseCustomerVM;
    CustomerVm customerVm;

    public void setCustomerVm(CustomerVm customerVm) {
        this.customerVm = customerVm;
    }

    public CustomerItemVM(@NonNull BaseViewModel viewModel, CustomerBean.DataDTO bean) {
        super(viewModel);
        info.set(bean);

    }

    public void setChooseCustomerVM(ChooseCustomerVM chooseCustomerVM) {
        this.chooseCustomerVM = chooseCustomerVM;
    }

    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Intent intent = new Intent();
            intent.putExtra("data",info.get());
            chooseCustomerVM.mActivity.setResult(10087,intent);
            chooseCustomerVM.finish();
        }
    });

    public BindingCommand lookClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle intent = new Bundle();
            intent.putString(BUNDLE_KEY,info.get().getId()+"");
            intent.putString(AppConfig.BUNDLE_KEY2,"person");
            customerVm.startActivity(CustomerInfoActivity.class,intent);
        }
    });

    public BindingCommand callClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            ValidateUtils.callPhone(customerVm.mActivity,info.get().getPhone());
        }
    });

    public BindingCommand msmClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            ValidateUtils.msnPhone(customerVm.mActivity,info.get().getPhone());
        }
    });


}
